
/**
 * This class provide methods for creating control message 
 * which is to be communicated between client and server.
 * 
 * @author pkulkar@ncsu.edu
 */
package com.android.networking.message;
import java.net.InetAddress;

public class ControlMessage {
	ControlPacket localPack;
	public ControlMessage(String destinationIP,int destinationPort,int sourceConnID,
			String muticastIP,int score,int lengthOfExtraData,String extraData){
		try{
		    localPack = new ControlPacket();
		    localPack.setDestinationIP(destinationIP);
		    localPack.setDestinationPort(destinationPort);
		    localPack.setSourceConnID(sourceConnID);
		    localPack.setSourceIP(InetAddress.getLocalHost().getHostAddress());
		    localPack.setSourcePort(destinationPort);
		    localPack.setExtraData(extraData);
		    localPack.setLengthOfExtraData(lengthOfExtraData);
		    localPack.setMuticastIP(muticastIP);
		    localPack.setScore(score);
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	public ControlPacket getControlPacket(){
		return localPack;
	}
	public void createNewConnection(){
		try{
			localPack.setRequestType(ControlRquestType.NEW_CONNECTION);
			localPack.computeChecksum();
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	
	public void assignMulticastID(){
		try{
			localPack.setRequestType(ControlRquestType.MUTICAST_ID_ASSIGNEMT);
			localPack.computeChecksum();
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	
	public void clientClose(){
		try{
			localPack.setRequestType(ControlRquestType.CLIENT_CLOSE);
			localPack.computeChecksum();
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	
	public void clientCloseAck(){
		try{
			localPack.setRequestType(ControlRquestType.CLIENT_CLOSE_ACK);
			localPack.computeChecksum();
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	
	public void serverClose(){
		try{
			localPack.setRequestType(ControlRquestType.SERVER_CLOSE);
			localPack.computeChecksum();
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	
	public void serverCloseAck(){
		try{
			localPack.setRequestType(ControlRquestType.SERVER_CLOSE_ACK);
			localPack.computeChecksum();
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	
	public void testConnection(){
		try{
			localPack.setRequestType(ControlRquestType.CONNECTION_TEST);
			localPack.computeChecksum();
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	
	public void testConnectionAck(){
		try{
			localPack.setRequestType(ControlRquestType.CONNECTION_TEST_ACK);
			localPack.computeChecksum();
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	
	public void reqeustScore(){
		try{
			localPack.setRequestType(ControlRquestType.SCORE_REQUEST);
			localPack.computeChecksum();
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	
	public void reqeustScoreAck(){
		try{
			localPack.setRequestType(ControlRquestType.SCORE_REQUEST_ACK);
			localPack.computeChecksum();
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
		
	public void reqeustScoreResponse(){
		try{
			localPack.setRequestType(ControlRquestType.SCORE_RESPONSE);
			localPack.computeChecksum();
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}

	public void reqeustScoreResponseAck(){
		try{
			localPack.setRequestType(ControlRquestType.SCORE_RESPONSE_ACK);
			localPack.computeChecksum();
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	public void canvasClear(){
		try{
			localPack.setRequestType(ControlRquestType.CANVAS_CLEAR);
			localPack.computeChecksum();
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	
	public void canvasClearAck(){
		try{
			localPack.setRequestType(ControlRquestType.CANVAS_CLEAR_ACK);
			localPack.computeChecksum();
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	
	public void displayControlMessage(){
		localPack.displayControlPacket();
	}
	
	public String getMuticastIP() {
		return localPack.getMuticastIP();
	}

	public int getScore() {
		return localPack.getScore();
	}

	public int getLengthOfExtraData() {
		return localPack.getLengthOfExtraData();
	}

	public String getExtraData() {
		return localPack.getExtraData();
	}

	public int getRequestType() {
		return localPack.getRequestType();
	}

	public String getSourceIP() {
		return localPack.getSourceIP();
	}

	public int getSourcePort() {
		return localPack.getSourcePort();
	}

	public String getDestinationIP() {
		return localPack.getDestinationIP();
	}

	public int getDestinationPort() {
		return localPack.getDestinationPort();
	}

	public int getSourceConnID() {
		return localPack.getSourceConnID();
	}
}
